package com.lwt.yygh.hosp.controller;

import com.lwt.yygh.common.result.Result;
import com.lwt.yygh.hosp.service.HospitalService;
import com.lwt.yygh.model.hosp.Hospital;
import com.lwt.yygh.vo.hosp.HospitalQueryVo;
import com.lwt.yygh.vo.hosp.HospitalSetQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 从MongoDB中操作数据
 * @Author Weton Li
 * @Date 2021/4/24 22:27
 */
@RestController
@RequestMapping("/admin/hosp/hospital")
@CrossOrigin
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    /**
     * 医院分页+条件查询 按市按关键字
     * @param page
     * @param limit
     * @param hospitalQueryVo
     * @return
     */
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable("page") Integer page,
                           @PathVariable("limit") Integer limit,
                           HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageModel = hospitalService.selectHospPage(page,limit,hospitalQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 医院的上下线
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "更新医院上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }

    /**
     * 医院的等级市区+预约信息（详情按钮->进入新页面）
     * @param id
     * @return
     */
    @ApiOperation(value = "医院详情")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(@PathVariable String id){
        Map<String, Object> hospByIdMap = hospitalService.getHospById(id);
        return Result.ok(hospByIdMap);
    }

}
